﻿using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class D_Order : IOrder
    {
        public void Add(Order item)
        {
            CakeEntities db = new CakeEntities();
            db.Order.Add(item);
            db.SaveChanges();
        }

        public void Delete(int id)
        {
            CakeEntities db = new CakeEntities();
            db.Order.Remove(db.Order.Find(id));
            db.SaveChanges();
        }

        public Order FindById(int id)
        {
            CakeEntities db = new CakeEntities();
            return db.Order.Find(id);
        }

        public List<Order> GetAll()
        {
            CakeEntities db = new CakeEntities();
            return db.Order.ToList();
        }

        public void Updata(int id, Order item)
        {
            CakeEntities db = new CakeEntities();
            var data=db.Order.Find(id);
            if (data != null)
            {
                data.OrderNum = item.OrderNum;
                data.status = item.status;
                data.CreateDate = item.CreateDate;
                data.Total = item.Total;
                data.Freight = item.Freight;
                data.CustomerId = item.CustomerId;
                data.AddressId = item.AddressId;
                data.Leave= item.Leave;
                data.Invoice=item.Invoice;
                data.Notes = item.Notes;
                data.Date = item.Date;
                data.Hour = item.Hour;
                db.SaveChanges();
            }
        }
    }
}
